﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla.Data;

namespace Accounting.Library.GhiSo
{
    public class GhiSoMSP_MuaDichVu : GhiSoService
    {

        public GhiSoMSP_MuaDichVu(object ChungTu) : base(ChungTu) { }

        public override void GhiSoChiTiet(ContextManager<Accounting.DataAccess.AccountingDataContext> ctx)
        {
            DataAccess.MSP_MuaDichVu parent = (DataAccess.MSP_MuaDichVu)ChungTu;

            //if ((!(bool)parent.DaThanhToan) && (!(bool)parent.LaChiPhiMuaHang))
            //{
                LoaiChungTuId = BusinessConfiguration.Configuration.LoaiChungTuId_MSP_MuaDichVu;
                NgayChungTu = parent.NgayChungTu;
                NgayHachToan = parent.NgayHachToan;
                SoHD = parent.Ma;

                #region MSP_MuaDichVu_ChiPhiMuaDichVu
                foreach (DataAccess.MSP_MuaDichVu_ChiPhiMuaDichVu child in parent.MSP_MuaDichVu_ChiPhiMuaDichVus)
                {
                    if (child.SoTienQĐ != null)
                    {
                        if (!child.SoTienQĐ.Equals(0))
                        {
                            //Su dung store procedure nay để add dữ liệu vào trong so chi tiet
                            ctx.DataContext.addTH_SoChiTiet(ref Khoa, child.ChungTuGocId, child.Khoa, LoaiChungTuId,
                                NgayChungTu, NgayHachToan, SoHD, child.TkNoId, child.TkCoId, child.DienGiai, child.SoTienQĐ, KyKetChuyenId,
                                BusinessConfiguration.Configuration.CHITIET, child.DoiTuongTHCPId, child.HangHoa);
                        }
                    }
                } 
                #endregion

                #region MSP_MuaDichVu_ChiTiet
                foreach (DataAccess.MSP_MuaDichVu_ChiTiet child in parent.MSP_MuaDichVu_ChiTiets)
                {
                    if (child.ThanhTien != null)
                    {
                        if (!child.ThanhTienQĐ.Equals(0))
                        {
                            //Su dung store procedure nay để add dữ liệu vào trong so chi tiet
                            ctx.DataContext.addTH_SoChiTiet(ref Khoa, child.ChungTuGocId, child.Khoa, LoaiChungTuId,
                                NgayChungTu, NgayHachToan, SoHD, child.TKNoId, child.TKCoId, child.DienGiai, child.ThanhTienQĐ, KyKetChuyenId,
                                BusinessConfiguration.Configuration.CHITIET, child.DoiTuongTHCPId, child.HangHoa);
                        }
                    }
                } 
                #endregion

                #region MSP_MuaDichVu_Thue
                foreach (DataAccess.MSP_MuaDichVu_Thue child in parent.MSP_MuaDichVu_Thues)
                {
                    if (child.TienThueGTGTQĐ != null)
                    {
                        if (!child.TienThueGTGTQĐ.Equals(0))
                        {
                            SoHD = child.SoHD;
                            //Su dung store procedure nay để add dữ liệu vào trong so chi tiet
                            ctx.DataContext.addTH_SoChiTiet(ref Khoa, child.ChungTuGocId, child.Khoa, LoaiChungTuId,
                                NgayChungTu, NgayHachToan, SoHD, child.TKNoId, child.TKCoId, child.DienGiai, child.TienThueGTGTQĐ, KyKetChuyenId,
                                BusinessConfiguration.Configuration.THUE_GTGT, null, null);
                        }
                    }
                }
                #endregion
            //}
        }
    }
}
